"use strict";

/**以特定时间日期格式返回当前时间日期、旧版
 * @deprecated
 * */
function getCusFmtTimeDate(dateFmt, timeFmt, weekFmt) {
    let datetime = new Date();
    let EngWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    let ChsWeek = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];

    /**最终拼合**/
    let finaldateFmt = "";
    let finaltimeFmt = "";
    let finalweekFmt = "";
    /**最终拼合**/

    /**参数表示符**/
    let paret1 = "";
    let paret2 = "";
    let paret3 = "";
    /**参数表示符**/

    /**临时数据存储块**/
    let tempsave1 = "";
    let tempsave2 = "";
    let tempsave3 = "";
    /**临时数据存储块**/

    /**锁定器**/
    let genicfmtd1 = false;
    let genicfmtd2 = false;
    let genicfmtd3 = false;
    /**锁定器**/

    /**日期处理*/
    if (dateFmt === "" || dateFmt === undefined) {
        dateFmt = "yyyy/mm/dd"; //设置默认值
    }
    for (let ione = 0; ione <= dateFmt.length; ione++) {
        /**年份标识符处理**/
        if (dateFmt.charAt(ione) === 'y' || dateFmt.charAt(ione) === "Y") {
            //符合条件的
            paret1 = paret1 + dateFmt.charAt(ione); //拼接字符，获得标识符串，用以获取长度
            genicfmtd1 = true; //锁定器解锁
        } else {
            if (genicfmtd1 === true) {
                tempsave1 = tempsave1 + datetime.getFullYear(); //读取系统中的年份数据
                tempsave1 = tempsave1.substr(tempsave1.length - paret1.length); //根据paret1的长度数来裁剪需要的数据
                if (dateFmt.charAt(ione) !== "" && dateFmt.charAt(ione) !== undefined) {
                    //判断是否还有字符，有就拼接进去
                    tempsave1 = tempsave1 + dateFmt.charAt(ione);
                }
                finaldateFmt = finaldateFmt + tempsave1; //把已经裁剪好的数据拼接赋值到finaldateFmt
                paret1 = ""; //清空参数表示块
                tempsave1 = ""; //清空临时存储块
                genicfmtd1 = false; //锁定器锁定
            }
        }
        /**年份标识符处理**/

        /**月份标识符处理**/
        if (dateFmt.charAt(ione) === 'm' || dateFmt.charAt(ione) === "M") {
            paret2 = paret2 + dateFmt.charAt(ione);
            genicfmtd2 = true;
        } else {
            if (genicfmtd2 === true) {
                tempsave2 = tempsave2 + (datetime.getMonth() + 1);
                tempsave2 = tempsave2.substr(2 - paret2.length);
                if (dateFmt.charAt(ione) !== "" && dateFmt.charAt(ione) !== undefined) {
                    tempsave2 = tempsave2 + dateFmt.charAt(ione);
                }
                finaldateFmt = finaldateFmt + tempsave2;
                paret2 = "";
                tempsave2 = "";
                genicfmtd2 = false;
            }
        }
        /**月份标识符处理**/

        /**日期标识符处理**/
        if (dateFmt.charAt(ione) === 'd' || dateFmt.charAt(ione) === 'D') {
            paret3 = paret3 + dateFmt.charAt(ione);
            genicfmtd3 = true;
        } else {
            if (genicfmtd3 === true) {
                tempsave3 = tempsave3 + datetime.getDate();
                tempsave3 = tempsave3.substr(tempsave3.length - paret3.length);
                if (dateFmt.charAt(ione) !== "" && dateFmt.charAt(ione) !== undefined) {
                    tempsave3 = tempsave3 + dateFmt.charAt(ione);
                }
                finaldateFmt = finaldateFmt + tempsave3;
                paret3 = "";
                tempsave3 = "";
                genicfmtd3 = false;
            }
        }
        /**日期标识符处理**/
    }
    /**日期处理*/

    /**时间处理*/
    if (timeFmt === "" || timeFmt === undefined) {
        timeFmt = "HH:MM";
    }
    for (let itwo = 0; itwo <= timeFmt.length; itwo++) {
        if (timeFmt.charAt(itwo) === "h" || timeFmt.charAt(itwo) === "H") {
            paret1 = paret1 + timeFmt.charAt(itwo);
            genicfmtd1 = true;
        } else {
            if (genicfmtd1 === true) {
                tempsave1 = tempsave1 + datetime.getHours();
                tempsave1 = tempsave1.substr(tempsave1.length - paret1.length);
                if (timeFmt.charAt(itwo) !== "" && timeFmt.charAt(itwo) !== undefined) {
                    tempsave1 = tempsave1 + timeFmt.charAt(itwo);
                }
                finaltimeFmt = finaltimeFmt + tempsave1;
                paret1 = "";
                tempsave1 = "";
                genicfmtd1 = false;
            }
        }

        if (timeFmt.charAt(itwo) === "m" || timeFmt.charAt(itwo) === "M") {
            paret2 = paret2 + timeFmt.charAt(itwo);
            genicfmtd2 = true;
        } else {
            if (genicfmtd2 === true) {
                tempsave2 = tempsave2 + datetime.getMinutes();
                tempsave2 = tempsave2.substr(tempsave2.length - paret2.length);
                if (timeFmt.charAt(itwo) !== "" && timeFmt.charAt(itwo) !== undefined) {
                    tempsave2 = tempsave2 + timeFmt.charAt(itwo);
                }
                finaltimeFmt = finaltimeFmt + tempsave2;
                paret2 = "";
                tempsave2 = "";
                genicfmtd2 = false;
            }
        }

        if (timeFmt.charAt(itwo) === "s" || timeFmt.charAt(itwo) === "S") {
            paret3 = paret3 + timeFmt.charAt(itwo);
            genicfmtd3 = true;
        } else {
            if (genicfmtd3 === true) {
                tempsave3 = tempsave3 + datetime.getSeconds();
                tempsave3 = tempsave3.substr(tempsave3.length - paret3.length);
                if (timeFmt.charAt(itwo) !== undefined && timeFmt.charAt(itwo) !== "") {
                    tempsave3 = tempsave3 + timeFmt.charAt(itwo);
                }
                finaltimeFmt = finaltimeFmt + tempsave3;
                paret3 = "";
                tempsave3 = "";
                genicfmtd3 = false;
            }
        }
    }
    /**时间处理*/

    /**星期的处理**/
    if (weekFmt === "" || weekFmt === undefined || weekFmt === "Eng") {
        finalweekFmt = EngWeek[datetime.getDay()];
    } else if (weekFmt === "Chs") {
        finalweekFmt = ChsWeek[datetime.getDay()];
    }
    /**星期的处理**/

    return (finaldateFmt + " " + finaltimeFmt + " " + finalweekFmt);
}

/**以特定时间日期格式返回当前时间日期、新版*/
function getCustomFormatTimeDate() {

/*    console.error("处于开发测试阶段！");
    return;
    let getCustomFormatTimeDateTools = this;
    let NeedImp = getCustomFormatTimeDateTools.lightCopy(getCustomFormatTimeDateTools);
    NeedImp.DataTypeDetect({
        _GlobalOperate: {
            enableDict: true, bind: {
                String: {aliasVal: "str", aliasDsc: "为字符串类型"},
                Array: {aliasVal: "arr", aliasDsc: "为数组类型"},
                Object: {aliasVal: "obj", aliasDsc: "为对象类型"},
                Boolean: {aliasVal: "boo", aliasDsc: "为布尔类型"},
                Number: {aliasVal: "num", aliasDsc: "为数字类型"},
                Undefined: {aliasVal: "und", aliasDsc: "未知定义类型"},
                Function: {aliasVal: "fun", aliasDsc: "为函数类型"},
                AsyncFunction: {aliasVal: "anf", aliasDsc: "为异步函数类型"},
                Null: {aliasVal: "nul", aliasDsc: "为空数据类型"},
                process: {aliasVal: "pro", aliasDsc: "Node JS Process对象"}
            }, RetValueType: 0
        }
    });

    /!**操作常量*!/
    const operateMessageStatic = {
        defaultGet: 0
    }

    /!**当前的操作消息*!/
    let currentOperateMessage;

    let FmtSymbolBase = ['y', 'd', 'm', 'h', 's', ','];
    let FinalDisplayWeekArr;
    let dateFmt;
    let timeFmt;
    let getConfigData;
    let detectValue;

    /!**字符串形参参数分析*!/
    function StringParameterAnalyse(NeedSourceData) {
        function detectFormat(value) {
            let detectBody = {
                exist_y: NeedImp.findMultiEqualString(value, "y", false, 0, 0),
                exist_d: NeedImp.findMultiEqualString(value, "d", false, 0, 0),
                exist_m: NeedImp.findMultiEqualString(value, "m", false, 0, 0),
                exist_h: NeedImp.findMultiEqualString(value, "h", false, 0, 0),
                exist_s: NeedImp.findMultiEqualString(value, "s", false, 0, 0),
                exist_chn: NeedImp.findMultiEqualString(value, "chn", false, 0, 0),
                exist_eng: NeedImp.findMultiEqualString(value, "eng", false, 0, 0)
            }
            let tmps;
            for (let ItemName in detectBody) {
                if (parseInt(detectBody[ItemName]) > 0) {
                    switch (String(ItemName).toLowerCase()) {
                        case  "exist_y":
                            break;
                        case "exist_d":
                            break;
                        case "exist_m":
                            if (detectBody.exist_h > 0) {
                                if (tmps === undefined) {
                                    tmps = "h";
                                } else {
                                    tmps = tmps + "h"
                                }
                                tmps = tmps + "m"
                            }
                            if (detectBody.exist_s > 0) {
                                tmps = tmps + "s"
                            }
                            break;
                        case "exist_h":
                            if (tmps === undefined) {
                                tmps = "h"
                            } else {
                                if (String(tmps).indexOf("h") <= -1) {
                                    tmps = "h" + tmps;
                                }
                            }
                            if (detectBody.exist_m > 0) {
                                if (String(tmps).indexOf("m") <= -1) {
                                    tmps = tmps + "m";
                                }
                            }
                            if (detectBody.exist_s > 0) {
                                if (String(tmps).indexOf("s") <= -1) {
                                    tmps = tmps + "s";
                                }
                            }
                            break;
                        case "exist_s":
                            if (detectBody.exist_h > 0) {
                                if (String(tmps).indexOf("h") <= -1) {
                                    tmps = "h" + tmps;
                                }
                            }
                            if (detectBody.exist_m > 0) {
                                if (String(tmps).indexOf("m") <= -1) {
                                    tmps = "m" + tmps;
                                }
                            }
                            break;
                        case "exist_chn":
                            break;
                        case "exist_eng":
                            break;
                    }
                }
            }
            console.log(tmps)
            switch (tmps) {
                case "hms":
                    return "time";
                case "hm":
                    return "time";
                case "ydm":
                    break;
                default:
                    break;
            }
        }

        if (NeedImp.DataTypeDetect(NeedSourceData) === "arr" && Array(...NeedSourceData).length > 0) {
            for (let num in NeedSourceData) {
                if (typeof NeedSourceData[num] === "string") {
                    detectValue = detectFormat(NeedSourceData[num]);
                    switch (detectValue) {
                        case "time":
                            break;
                        case "date":
                            break;
                        case "week":
                            break;
                        default:
                            throw new Error("格式异常！");
                    }
                } else {
                    throw new Error("非字符串数据！");
                }
            }
        } else {
            throw new Error("无效数组！");
        }
    }

    let tempProc

    let NeedProc_time;
    let NeedProc_date;
    let NeedProc_week;

    switch (arguments.length) {
        case 1:
            switch (NeedImp.DataTypeDetect(arguments[0])) {
                case "obj":
                    break;
                case "str":
                    let splitSymNum = NeedImp.findMultiEqualString(arguments[0], ",", true, 0, 0);
                    if (splitSymNum > 3) {
                        throw new Error("要求生成的格式过多！");
                    }

                    tempProc = String(arguments[0]).split(",");
                    StringParameterAnalyse(tempProc);
                    break;
                default:
                    throw new Error("传递过来的参数异常！");
            }
            break;
        default:
            if (arguments.length > 1) {
                throw new Error("参数过多，无法识别！@#￥%……");
            } else {
                currentOperateMessage = operateMessageStatic.defaultGet;
            }
    }*/
}

module.exports = {getCusFmtTimeDate, getCustomFormatTimeDate};
